var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/Upload/utils.ts
var utils_exports = {};
__export(utils_exports, {
  convetAliasToExtension: () => convetAliasToExtension,
  createFileValidator: () => createFileValidator
});
module.exports = __toCommonJS(utils_exports);
var import_utils = require("@szzj/utils");
var import_Mime = __toESM(require("mime/Mime"));
var import_standard = __toESM(require("mime/types/standard.js"));
var import_other = __toESM(require("mime/types/other.js"));
var mime = new import_Mime.default(import_standard.default, import_other.default);
var Alias = {
  image: ".png,.apng,.avif,.gif,.jpeg,.svg,.webp,.bmp,.ico,.jfif,.pjpeg,.pjp",
  audio: ".mp3,.wav,.wma,.ogg,.aac,.flac,.m4a",
  vedio: ".mp4,.avi,.rmvb,.rm,.wmv,.mkv,.flv,.mov",
  word: ".doc,.docx",
  excel: ".xls,.xlsx",
  pdf: ".pdf",
  ppt: ".ppt,.pptx"
};
var convetAliasToExtension = (accept) => {
  return accept.split(",").map((type) => {
    return Alias[type] ?? type;
  }).join(",");
};
var validateFileType = (file, {
  accept,
  errorMessages
}) => {
  const accepted = accept.split(",").some((type) => {
    const names = file.name.split(".");
    const extension = `.${names[names.length - 1]}`;
    return extension === type || file.type === type || !!(mime.getType(type) && file.type === mime.getType(type));
  });
  if (!accepted) {
    const msg = (0, import_utils.template)(errorMessages == null ? void 0 : errorMessages.typeError)({ accept });
    throw new Error(msg);
  }
};
var validateFileSize = (file, {
  maxSize,
  errorMessages
}) => {
  const lessThenMaxSize = file.size / 1024 / 1024 < maxSize;
  if (!lessThenMaxSize) {
    const msg = (0, import_utils.template)(errorMessages == null ? void 0 : errorMessages.overSize)({ maxSize });
    throw new Error(msg);
  }
};
var createFileValidator = ({
  accept,
  maxSize,
  errorMessages
}) => {
  return (file) => {
    if (accept) {
      validateFileType(file, {
        accept,
        errorMessages
      });
    }
    if (maxSize) {
      validateFileSize(file, {
        maxSize,
        errorMessages
      });
    }
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  convetAliasToExtension,
  createFileValidator
});
